package com.qf.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2//开始swagger支持
@Configuration//纳入容器中
public class SwaggerConfig {


    @Bean
    public Docket docket(Environment environment){
        Profiles profiles= Profiles.of("dev");//判断是否是开发阶段，如果是的话就生成，如果不是的话就不生成
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(flag)
                .groupName("ssp").select().apis(RequestHandlerSelectors.basePackage("com.qf.controller")).build();
    }

    private ApiInfo apiInfo(){
        final Contact DEFAULT_CONTACT = new Contact("第一组--宋世平", "http://www.hopeurl.life", "2453332538@qq.com");
        return new ApiInfo("SpringBoot-Vue", "这是一个基于SpringBoot以及Vue的开源项目", "1.0", "http://www.hopeurl.life",
                DEFAULT_CONTACT, "Apache 2.0", "", new ArrayList<>());
    }
}
